<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 
      很多情况下，可能计算属性和侦听属性都能用
      优先选择计算属性（计算属性缓存，计算属性允许同时依赖多个响应式数据更方便）

      只有当出现异步的时候，只能选择侦听器
     -->
    <div id="app">
      <label>firstname:</label>
      <input type="text" v-model="firstname" />
      +
      <label>lastname:</label>
      <input type="text" v-model="lastname" />
      =
      <span>{{ fullname }}</span>
    </div>

    <script src="./lib/Vue3.js"></script>
    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {
            firstname: "xiao",
            lastname: "hua",
            // fullname: "xiaohua",
          };
        },
        // watch: {
        //   firstname(val) {
        //     this.fullname = val + this.lastname;
        //   },
        //   lastname(val) {
        //     this.fullname = this.firstname + val;
        //   },
        // },

        computed: {
          fullname() {
            return this.firstname + this.lastname;
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
